package com.clstu.homeworks.homework07;

public class HomeWork07 {
    public static void main(String[] args) {
        Person[] arr=new Person[4];//定义多态数组，向上转型
        HomeWork07 tool = new HomeWork07();
        Person t = new Person("Trunp", 60, "man");
        arr[0]=new Student("jack",20,"man","2020212333");
        arr[1]=new Student("anne",19,"woman","2020212334");
        arr[2]=new Teacher("Frank",16,"man",2);
        arr[3]=new Teacher("Fcuk",23,"man",6);
        Person temp=null;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i].getAge()>arr[j].getAge()){
                    temp=arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i].printInfo();
            tool.ts(arr[i]);
            System.out.println("==================================");
        }
        tool.ts(t);

    }

    public void ts(Person p){//多态参数，向下转型调用子类特有属性或方法
        if(p instanceof Teacher){
            ((Teacher)p).teach();
        }
        else if(p instanceof Student){
            ((Student)p).study();
        }
        else
            System.out.println("传参不正确，只能是Person的子类");
    }

}
